package org.altervista.cp.microkernel.persistence.spi;

import java.sql.ResultSet;
import java.sql.SQLException;

public class DefaultLoader<T> extends FieldIntrospector<T> implements Loader<T> {

	public DefaultLoader(Class<? extends T> c) {
		super(c);
	}

	public void set(T o, ResultSet rs) throws SQLException {
		try {
			for (int i = 0, n = _fields.length; i < n; i++) {
				_fields[i].set(o, rs.getObject(_fields[i].getName()
						.substring(1)));
			}
			for (int i = _fields.length, n = _idFields.length; i < n; i++) {
				_idFields[i].set(o, rs.getObject(_fields[i].getName()
						.substring(4)));
			}
		} catch (SQLException e) {
			throw e;
		} catch (Exception e) {
			throw new IllegalStateException(e);
		}

	}

}
